<template>
<div class="UserPostList">
<van-nav-bar
  title="帖子列表"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>
<van-sticky>
<van-dropdown-menu>
  <van-dropdown-item v-model="value1" :options="option1" @change="onChangeType"/>
  <van-dropdown-item v-model="value2" :options="option2" @change="onChangeStatus"/>
</van-dropdown-menu>
</van-sticky>


<van-list
  v-model="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"
>

<van-cell v-for="item in list" :key="item.id" :title="item.content" @click="onClickPost(item.id)" />

</van-list>

<div style="height:100px"></div>

</div>
</template>

<script>

export default {
  name: 'UserPostList',
  props: {

  },
  data() {
    return {
      value1: 0,
      value2: '0',
      option1: [
        ////  '内容类型ID（1我要晒机2配置清单3闲聊灌水）',
        { text: '全部帖子', value: 0 },
        { text: '我要晒机', value: 1 },
        { text: '配置清单', value: 2 },
      ],
      option2: [
        { text: '待审核', value: '0' },
        { text: '审核通过', value: '1' }

      ],

      list: [],
      loading: false,
      finished: false,
      page: 0,//
    };
  },
  methods: {

      onChangeType(value){
        this.value1 = value

        this.list  = []
        this.loading = false
        this.finished =  false
        this.page =  0
      },
      onChangeStatus(value){
        this.value2 = value

        this.list  = []
        this.loading = false
        this.finished =  false
        this.page =  0
      },

      onLoad() {

        var formData = new FormData()

        formData.append('type', this.value1)
        formData.append('status', this.value2)
        formData.append('page', this.page)

        let that = this
        this.$axios
            .post('https://www.17fpv.com/wp-json/jiangqie/v1/userpost/post-list', formData)
            .then(response =>{
                if (response.data.code == 1)
                {
                  //失败
                    that.$toast.fail(response.data)
                }
                else
                {
                  //成功

                    if (response.data.data.list < 12)
                    {
                        that.finished = true
                    }


                    that.list = that.list.concat(response.data.data.list)
                    that.loading = false

                    that.page += 1

                }

            })
            .catch(function(error)
            {
                console.log(error)
            });
      },
      onClickPost(id){
        this.$router.push({
          path: '/admin/userpostedit',
          query: {
            id: id,
            status: this.value2
          }
        })
      },
      onClickLeft () {
        history.go(-1)
      },

   },



}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
